<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>公告</title>
<style type="text/css">
	@media screen{
	}
	body div {
		text-align: center;
	}
#PlatformName {
	height: 20%;
	width: 20%;
	text-align: center;
}
body {
	background-color: #17EBC0;
}
</style>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script> 	
<script>
$(document).ready(function(){
	$("#SaveVersion").click(function(){
		var BuildCode = $('#BuildCode').val();
		var VersionName = $('#VersionName').val();
		var Platfrom = $('#PlatformName option:selected').text();
		var Content = $('#Content').val();
		var Uid = 0;
		if(Platfrom == "Android"){
			Uid = 1;
		}
		if(Platfrom == "IOS"){
			Uid = 2;
		}
		alert("请填写BuildCode！" + VersionName + Platfrom + Content);
		var data = JSON.stringify({
				"BuildCode": parseInt(BuildCode),
				"VersionName": VersionName,				
				"Platfrom": Platfrom,				
				"Content": Content,				
				"Uid": Uid,				
		  });

		if (BuildCode == "") 
    	{
			alert("请填写BuildCode！");
			
			return ;
    	}
		if (VersionName == "") 
    	{
			alert("请填写VersionName");
			
			return ;
    	}
		if (Uid == 0) 
    	{
			alert("请选择平台");
			
			return ;
    	}
		$.ajax({
			url:"/SaveVersion",
			async: true,
			data:data,
			type: "post",
			dataType: "json",
			headers: {
				"Content-Type": "application/json"
			},
			success:function(result){
				console.log("success:" + result);
				if(result.code == 200){
					alert("保存成功");	
				}
				if(result.code == 1){
					alert("bulidCode为数字");	
				}
				if(result.code == 2){
					alert("平台不能为空");	
				}
			},
			error: function () {
                alert("服务器发生了错误")
            }
		});
	});
	$("#formSave").submit(function(){
		return false;
	})
});
</script>
</head>
	
<body>
	{{template "home.html" .}}
	<div>
		<select name="PlatformName"  required="required" id="PlatformName">
			{{range .PlatformName}}
				<option value={{.}}>{{.}}</option>          
			{{end}}   
		</select>
				
	</div>
	<div>
		<p></p>
		<textarea name="Content" cols="30" rows="10" required="required" id="Content" placeholder="输入更新文本内容"></textarea>
	</div>
	<div>
		<form id="formSave" name="formSave" method="post">
			<p>
				<label for="Name"> BuildCode:</label>
				<input name="BuildCode" type="text" required="required" id="BuildCode" placeholder="GP版本号">
			</p>
			<p>
				<label for="password">VersionName:</label>
				<input name="VersionName" required="required" id="VersionName" placeholder="版本号">
			</p>
			<p>
				<input type="submit" id="SaveVersion" formaction="/" formmethod="POST" value="保存">    
			</p>
		</form>
	</div>
</body>
</html>
